package com.practice.Demo6_17.Array;

import com.practice.Demo6_17.Book;
import com.practice.Demo6_17.order;

import java.util.Scanner;

public class Test {
    public static void main(String ars[]){

        Book[] books=new Book[5];
        //Book[] books={b1,b2,b3};
        //Book[] books=new Book[]{b1,b2,b3};

        books[0]= new Book(1, "java", 33.3, 150);
        books[1]= new Book(2, "jsp", 56.6, 150);
        books[2]= new Book(3, "vue", 100.25, 150);
        books[3]= new Book(4, "html", 20.66, 150);
        books[4]= new Book(5, "mysql", 70.00, 150);

        order[] orders=new order[]{new order(),new order(),new order(),new order(),new order()};

        System.out.println("-----------欢迎进入图书馆-----------");
        System.out.println("书籍展示如下：");

        System.out.println("书籍编号  书籍名称  书籍价格  书籍库存");
        for (int i = 0; i <books.length ; i++) {
            System.out.println("  "+books[i].getBookno()+"      "+books[i].getName()+"    "
                    +books[i].getPrice()+"    "+books[i].getCount());
        }
        int flag=0;
        int num=0;
        int order_count=0;
        Scanner input = new Scanner(System.in);
        while (flag!=-1){

            System.out.println("请输入要购买的书籍编号（int）/退出请输入 -1 ");
            flag = input.nextInt();
            if (flag==-1){
             break;
            }else{
                System.out.println("请输入购买数量：");
                num=input.nextInt();
                orders[order_count].name=books[flag-1].getName();
                orders[order_count].num=num;
                orders[order_count].price=books[flag-1].getPrice();
            }
            order_count++;
            System.out.println("请继续购买书籍。。。");
        }
        System.out.println("订单总额为："+order.PayTotal(orders,order_count));
        for (int i = 0; i <order_count; i++) {
            orders[i].Show();
        }
    }
}
